package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Date;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    //新增操作时调用
    //meta0bject对象是MP自动填充的配置有默认行为
    @Override
    public void insertFill(MetaObject metaObject) {
     Date date=new Date();
     this.setFieldValByName("created",date,metaObject);
     this.setFieldValByName("updated",date,metaObject);
    }

    //更新操作时调用
    @Override
    public void updateFill(MetaObject metaObject) {
    Date date=new Date();
    this.setFieldValByName("updated",date,metaObject);
    }
}